package com.mmall.concurrency.example.singleton;

import com.mmall.concurrency.annotions.NotRecommends;
import com.mmall.concurrency.annotions.ThreadSafes;
import org.hibernate.validator.internal.util.stereotypes.ThreadSafe;

/**
 * 懒汉模式
 * 单例实例在第一次使用时进行创建
 *
 * @author Diamon.Cheng
 * @date 2019/12/5.
 */
@ThreadSafes
@NotRecommends
public class SingletonExample_3 {
    private  SingletonExample_3(){
    
    }
    
    // 单例对象
    public static  SingletonExample_3 instance = null;
    
    
    // 静态的工厂方法
    public  static synchronized   SingletonExample_3 getInstance(){
    
        if (instance == null){
            instance = new SingletonExample_3();
        }
        return  instance;
    }
}
